package org.metasketch.editor.toolbox;

import org.metasketch.editor.timeline.SnapshotListener;
import org.metasketch.editor.timeline.SnapshotManager;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.control.Button;
import javafx.scene.layout.HBox;

public class GenericTools extends Group implements EventHandler<ActionEvent>,
		SnapshotListener {

	Button undo = new Button("Undo");
	Button redo = new Button("Redo");

	public GenericTools() {

		SnapshotManager.addListener(this);

		HBox hbox = new HBox();

		getChildren().add(hbox);

		undo.setDisable(true);
		redo.setDisable(true);

		hbox.getChildren().addAll(undo, redo);

		undo.setOnAction(this);
		redo.setOnAction(this);
	}

	@Override
	public void handle(ActionEvent event) {
		Object source = event.getSource();
		if (source == undo) {
			SnapshotManager.undo();
			event.consume();
		} else if (source == redo) {
			SnapshotManager.redo();
			event.consume();
		}

	}

	@Override
	public void changedHistory() {
		undo.setDisable(!SnapshotManager.canUndo());
		redo.setDisable(!SnapshotManager.canRedo());
	}

}
